package order.dao;


import jdk.nashorn.internal.ir.RuntimeNode;
import order.pojo.manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 完成对店主表的增删改查
 */



public class managerDao {
    //querryAll
    public List<manager> querrAllManager(Connection con) throws SQLException {
        List<manager> list= new ArrayList<manager>();
        String sql="select * from manager order by manager_id";
        PreparedStatement pstm=con.prepareStatement(sql);
        ResultSet rs=pstm.executeQuery();

        manager manager=null;
        while(rs.next()){
            manager=new manager();
            manager.setManager_id(rs.getInt("manager_id"));
            manager.setManager_account(rs.getString("manager_account"));
            manager.setManager_password(rs.getString("manager_password"));
            list.add(manager);
            System.out.println(list.toString());
        }
        return list;

    }


//根据id删除一个
    public int deleteManagerById(Connection con,Integer managerId)throws SQLException{
        String sql="delete from manager where manager_id=?";
        PreparedStatement pstm=con.prepareStatement(sql);
        pstm.setInt(1,managerId);
        return pstm.executeUpdate();

    }

    //修改用户通过id
    public  int updateManagerById(Connection con,manager manager,Integer managerId)throws SQLException{
        String sql="update manager set manager_id=?,manager_account=?,manager_password=? where manager_id=?";
        PreparedStatement pstm=con.prepareStatement(sql);
        pstm.setInt(1,manager.getManager_id() );
        pstm.setString(2,manager.getManager_account());
        pstm.setString(3,manager.getManager_password());
        pstm.setInt(4,managerId);


        return pstm.executeUpdate();
    }

    //增加一个顾客
    public  int addmanager(Connection con,manager manager)throws  SQLException{
        String sql="insert into manager values(?,?,?)";
        PreparedStatement pstm=con.prepareStatement(sql);
        pstm.setInt(1,manager.getManager_id());
        pstm.setString(2,manager.getManager_account());
        pstm.setString(3,manager.getManager_password());


        return pstm.executeUpdate();



    }


























}
